package com.ocom.ugcapi.controller;

import com.ocom.common.constant.WxServiceUrl;
import com.ocom.common.entity.human.EntityRoommateInfo;
import com.ocom.common.resp.Result;
import com.ocom.common.vo.human.AddRoommateCodeVo;
import com.ocom.common.vo.human.GetRoommateListVo;
import com.ocom.common.vo.human.RemoveRoommateVo;
import com.ocom.common.vo.ugcapi.GzhUserInfo;
import com.ocom.ugcapi.client.HumanClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2023/4/26
 **/
@RestController
public class RoomPersonController {
	@Autowired
	HumanClientService humanClientService;

	/**
	 * 3.13.1获取联系人列表(getRoommateList)
	 */
	@PostMapping(WxServiceUrl.URL_getRoommateList)
	public Result getRoommateList(@RequestBody Map<String,Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		GetRoommateListVo getRoommateListVo=new GetRoommateListVo();
		getRoommateListVo.setComId(userInfo.getComId());
		getRoommateListVo.setPId(userInfo.getPId().intValue());
		getRoommateListVo.setPage(1);
		getRoommateListVo.setSize(500);
		return humanClientService.GetRoommateList(getRoommateListVo);
	}

	/**
	 * 3.13.2 添加联系人(addRoommate)
	 */
	@PostMapping(WxServiceUrl.URL_addRoommate)
	public Result addRoommate(@RequestBody Map<String,Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");

		EntityRoommateInfo entityRoommateInfo=new EntityRoommateInfo();
		entityRoommateInfo.setComId(userInfo.getComId());
		entityRoommateInfo.setPId(userInfo.getPId());
		/**
		 * pName	姓名	string
		 * phone	手机号	string
		 * type	关系	string
		 * url	人脸图片	string
		 * callWay	支持通话	string ****
		 */
		entityRoommateInfo.setPhone((String) map.get("phone"));
		entityRoommateInfo.setName((String) map.get("pName"));
		entityRoommateInfo.setUrl((String) map.get("url"));
		entityRoommateInfo.setType((String) map.get("type"));
		return humanClientService.AddRoommate(entityRoommateInfo);
	}

	/**
	 * 3.13.3 更新联系人(updateRoommate)
	 */
	@PostMapping(WxServiceUrl.URL_updateRoommate)
	public Result updateRoommate(@RequestBody Map<String,Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");

		RemoveRoommateVo removeRoommateVo =new RemoveRoommateVo();
		removeRoommateVo.setComId(userInfo.getComId());
		removeRoommateVo.setPId(userInfo.getPId());
		removeRoommateVo.setId(((Integer) map.get("id")).longValue());
		humanClientService.RemoveRoommate(removeRoommateVo);
		EntityRoommateInfo entityRoommateInfo=new EntityRoommateInfo();
		entityRoommateInfo.setComId(userInfo.getComId());
		entityRoommateInfo.setPId(userInfo.getPId());
		/**
		 * pName	姓名	string
		 * phone	手机号	string
		 * type	关系	string
		 * url	人脸图片	string
		 * callWay	支持通话	string ****
		 */
		entityRoommateInfo.setPhone((String) map.get("phone"));
		entityRoommateInfo.setName((String) map.get("pName"));
		entityRoommateInfo.setUrl((String) map.get("url"));
		entityRoommateInfo.setType((String) map.get("type"));
		return humanClientService.AddRoommate(entityRoommateInfo);
	}

	/**
	 * 3.13.4 删除联系人(removeRoommate)
	 */
	@PostMapping(WxServiceUrl.URL_removeRoommate)
	public Result removeRoommate(@RequestBody Map<String,Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");

		RemoveRoommateVo removeRoommateVo =new RemoveRoommateVo();
		removeRoommateVo.setComId(userInfo.getComId());
		removeRoommateVo.setPId(userInfo.getPId());
		removeRoommateVo.setId(((Integer) map.get("id")).longValue());
		return humanClientService.RemoveRoommate(removeRoommateVo);
	}

	@PostMapping(WxServiceUrl.URL_addRoommateCode)
	public Result addRoommateCode(@RequestBody Map<String,Object> map) {
		GzhUserInfo userInfo  = (GzhUserInfo)map.get("userInfo");
		AddRoommateCodeVo addRoommateCodeVo = new AddRoommateCodeVo();
		addRoommateCodeVo.setComId(userInfo.getComId());
		addRoommateCodeVo.setPId(userInfo.getPId());
		return humanClientService.addRoommateCode(addRoommateCodeVo);
	}


}
